package com.xpqh.ksg.common.persistence.dao;

import com.xpqh.ksg.common.persistence.model.KsgProductInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xpqh.ksg.modular.core.dto.KsgProductListRespDTO;
import com.xpqh.ksg.modular.core.dto.KsgProductSeriesListRespDTO;
import com.xpqh.ksg.modular.core.dto.KsgWindowPriceRespDTO;
import com.xpqh.ksg.modular.core.dto.KsgWindowTypeListRespDTO;
import com.xpqh.ksg.modular.warranty.dto.KsgProductNameListRespDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 产品信息表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2025-04-18
 */
public interface KsgProductInfoMapper extends BaseMapper<KsgProductInfo> {

    @Select("SELECT product_name productName,id productId,introduce FROM ksg_product_info where type = 0")
    List<KsgProductNameListRespDTO> getProductNameList();

    @Select("SELECT product_name productName,id productId,introduce,window_type windowType FROM ksg_product_info where is_show = 0 and product_series = #{productSeries} and channel_type = #{channelType} and type = #{productType}")
    List<KsgProductNameListRespDTO> getProductNameListByChannel(@Param("productSeries")String productSeries, @Param("channelType")Integer channelType, @Param("productType")Integer productType);

    @Select("SELECT product_series seriesName,is_select_car_model isSelectCarModel FROM `ksg_product_info` a where is_show = 0 and type = #{productType} and channel_type = #{channelType} GROUP BY product_series ORDER BY (SELECT create_time from ksg_product_series where product_series = a.product_series) asc ")
    List<KsgProductListRespDTO> getProductList(@Param("productType")Integer productType, @Param("channelType")Integer channelType);

    @Select("SELECT product_name productName,id productId,introduce FROM ksg_product_info")
    List<KsgProductNameListRespDTO> getProductNameListAll();

    @Select("SELECT id productId,product_name productName,window_type windowType,introduce FROM ksg_product_info WHERE type = 1")
    List<KsgWindowTypeListRespDTO> getWindowTypeList();

    @Select("SELECT id productId,product_name productName,window_type windowType,introduce FROM ksg_product_info WHERE type = 1 and channel_type = #{channelType}")
    List<KsgWindowTypeListRespDTO> getWindowTypeListByChannelType(@Param("channelType")Integer channelType);

    @Select("SELECT id productId,introduce,product_name productName,IFNULL(IFNULL((SELECT price from ksg_series_details where series_id = #{carSeriesId} and product_series_id = a.id),default_price),0) price,window_type windowType FROM ksg_product_info a WHERE id in (${productIdList})")
    List<KsgWindowPriceRespDTO> getWindowPrice(@Param("carSeriesId") String carSeriesId, @Param("productIdList")String productIdList);
    
    @Select("SELECT id productId,introduce,product_name productName,IFNULL(default_price,0) price,window_type windowType FROM ksg_product_info a WHERE id in (${productIdList})")
    List<KsgWindowPriceRespDTO> getWindowPriceByType(@Param("productIdList")String productIdList);

    @Select("SELECT product_series productSeries,id productSeriesId,introduce  FROM ksg_product_info a where id = #{productId} ")
    List<KsgProductSeriesListRespDTO> getProductSeriesList(@Param("productId")Integer productId);

}

